package cn.xunjie.ymcc.mq;

import cn.xunjie.ymcc.domain.Course;
import cn.xunjie.ymcc.service.ICourseService;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup="course-consumer-group",
        topic="course-topic",
        selectorExpression="course-tags"
)
public class CourseConsummer implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseService courseService;
    @Override
    public void onMessage(MessageExt messageExt) {
        String s = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        Course course = JSONObject.parseObject(s, Course.class);
        courseService.commonmessages(course);
    }
}